package com.xteam.youin_supplier.adpter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.xteam.youin_supplier.R;
import com.xteam.youin_supplier.model.BeddingResulListItem;


/**
 * Created by Curry on 2015-12-16.
 */
public class TenderResultListViewAdapter extends RecyclerView.Adapter<TenderResultListViewAdapter.ViewHolder> implements View.OnClickListener {
    private Context mContext;
    private OnRecyclerViewItemClickListener mOnItemClickListener = null;

    BeddingResulListItem beddingResulListItem;
    public TenderResultListViewAdapter(Context context, BeddingResulListItem beddingResulListItem) {
        mContext = context;
        this.beddingResulListItem = beddingResulListItem;
    }
    @Override
    public void onClick(View view) {
        if (mOnItemClickListener != null) {
            //注意这里使用getTag方法获取数据
            mOnItemClickListener.onItemClick(view,(int)view.getTag());
        }
    }

    public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }

    //define interface
    public static interface OnRecyclerViewItemClickListener {
        void onItemClick(View view , int position);
    }




    @Override
    public TenderResultListViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.tender_result_title_item, parent, false);
        //将创建的View注册点击事件
        view.setOnClickListener(this);
        return  new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(TenderResultListViewAdapter.ViewHolder holder, int position) {
        holder.itemView.setTag(position);
//        int i = position % 3;
        if (beddingResulListItem.getData().get(position).getStatus() == 0) {
            holder.getRelativeLayout().setBackgroundColor(mContext.getResources().getColor(R.color.item_bg1));
        } else if (beddingResulListItem.getData().get(position).getStatus() == 4){
            holder.getRelativeLayout().setBackgroundColor(mContext.getResources().getColor(R.color.item_bg2));
        }else if(beddingResulListItem.getData().get(position).getStatus() == 3){
            holder.getRelativeLayout().setBackgroundColor(mContext.getResources().getColor(R.color.item_bg3));
        }

        holder.getAddr().setText(beddingResulListItem.getData().get(position).getName());
        holder.getNum().setText(beddingResulListItem.getData().get(position).getQty()+"");
        holder.getStatus().setText(beddingResulListItem.getData().get(position).getAcution_status());
        holder.getResul().setText(beddingResulListItem.getData().get(position).getCompetitive_status());
    }

    @Override
    public int getItemCount() {
        return beddingResulListItem.getData().size();
    }


    class ViewHolder extends RecyclerView.ViewHolder{
        private TextView addr;
        private TextView status;
        private TextView num;
        private TextView resul;
        private RelativeLayout relativeLayout;
        public ViewHolder(View itemView) {
            super(itemView);
            addr = (TextView) itemView.findViewById(R.id.tender_addr_content);
            status = (TextView) itemView.findViewById(R.id.tender_status_content);
            num = (TextView) itemView.findViewById(R.id.tender_num_content);
            resul = (TextView) itemView.findViewById(R.id.tender_result_content);
            relativeLayout = (RelativeLayout) itemView.findViewById(R.id.layout);
        }

        public TextView getAddr() {
            return addr;
        }



        public TextView getNum() {
            return num;
        }


        public TextView getStatus() {
            return status;
        }


        public TextView getResul() {
            return resul;
        }


        public RelativeLayout getRelativeLayout() {
            return relativeLayout;
        }

    }
}
